#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

typedef struct CircNode CircNode;

struct CircNode {
	CircNode* prev;
	int id;
	CircNode* next;
};

CircNode* createLinkedList(int size) {
	CircNode* head = 0;
	CircNode* current = 0;
	for (int i = 0; i < size; i++) {
		CircNode* newNode = (CircNode*)malloc(sizeof(CircNode));
		newNode->id = i + 1;

		if (i == 0) {
			head = newNode;
		} else {
			current->next = newNode;
			newNode->prev = current;
		}
		current = newNode;
	}
	current->next = head;
	head->prev = current;
	return head;
}

void removeNode(CircNode* node) {
	CircNode* prev = node->prev;
	CircNode* next = node->next;
	prev->next = next;
	next->prev = prev;
	free(node);
}

int main() {
	int size;
	int m;
	scanf("%d,%d", &size, &m);

	CircNode* p = createLinkedList(size);

	while (size > 1) {
		for (int i = 0; i < m; i++) {
			p = p->next;
		}
		printf("%d,", p->id);

		CircNode* t = p->next;
		removeNode(p);
		p = t;

		size--;
	}

	printf("%d", p->id);

}